#include "Graph.h"

// TODO: Collision detection based on rendering: render all objects to some buffer, use object ID (or even pointer to the object?) as color.

Graph::Graph(DWORD width, DWORD height)
{
	_width = width;
	_height = height;
	_buffer = new DWORD[_width * _height];
}


Graph::~Graph(void)
{
	delete [] _buffer;
}


void Graph::PutPixel(DWORD x, DWORD y, DWORD c)
{
	__asm 
	{
		Mov Eax, y
		Mov Esi, this
		Mov Ebx, [Esi]._width
		Mul Ebx
		Add Eax, x
		Shl Eax, 2 // Multiply by four
		Add Eax, [Esi]._buffer
		Mov Edi, Eax
		Mov Eax, c
		StosD
	}
}

DWORD* Graph::GetBuffer()
{
	return _buffer;
}